package com.code.zjm.binder.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.code.zjm.binder.demo.R;
import com.code.zjm.binder.demo.entity.Student;
import com.code.zjm.binder.demo.entity.Teacher;

import java.util.List;

/**
 * Created by ZJM on 2017/3/16.
 */

public class ShowStdActivity extends FragmentActivity {
    private ListView lv;
    private List<Student> students;
    private Teacher teacher;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_student);
        initData();
        initView();
    }

    public void initData() {
        teacher = getIntent().getParcelableExtra("studentList");
        students = teacher.getStudents();

    }

    public void initView() {
        lv = (ListView) findViewById(R.id.lv);
        lv.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, students));
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ShowStdActivity.this, ShowBookActivity.class);
                intent.putExtra("bookList", students.get(position));
                startActivity(intent);
            }
        });

    }
}
